@extends('layouts.admin')

@section('content')
    <a href="{{ route('admin.report.index') }}" class="layui-btn layui-btn-primary layui-btn-sm">返回</a>
    <hr>
    <form class="layui-form" action="" style="width: 90%;">

        <div class="layui-form-item">
            <label class="layui-form-label">报告编号：</label>
            <div class="layui-input-block">
                <input type="text" name="number" placeholder="报告编号" autocomplete="off" class="layui-input" value="{{ $report->number }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">项目位置：</label>
            <div class="layui-input-block">
                <input type="text" name="position" placeholder="项目位置" autocomplete="off" class="layui-input" value="{{ $report->position }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">委托方：</label>
            <div class="layui-input-block">
                <input type="text" name="client" placeholder="委托方" autocomplete="off" class="layui-input" value="{{ $report->client }}">
                <span style="color:red">* 多个委托方请用英文逗号(,)分割</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">总价：</label>
            <div class="layui-input-block">
                <input type="text" name="total_price" placeholder="总价" autocomplete="off" class="layui-input" value="{{ $report->total_price }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单价：</label>
            <div class="layui-input-block">
                <input type="text" name="price" placeholder="单价" autocomplete="off" class="layui-input" value="{{ $report->price }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">建成年代：</label>
            <div class="layui-input-block">
                <input type="text" name="built_in" placeholder="建成年代" autocomplete="off" class="layui-input" value="{{ $report->built_in }}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">产权性质：</label>
            <div class="layui-input-block">
                <input type="text" name="property_nature" placeholder="产权性质" autocomplete="off" class="layui-input" value="{{ $report->property_nature }}">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物理结构是否变化：</label>
            <div class="layui-input-block">
                <input type="radio" name="is_change" value="1" lay-filter="admin" title="有变化"
                       @if($report && $report->is_change == 1)
                       checked
                        @endif
                >
                <input type="radio" name="is_change" value="0" lay-filter="admin" title="无变化"
                       @if($report && $report->is_change == 0)
                       checked
                        @endif
                >
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{{ $report->id }}">
                <button class="layui-btn" lay-submit lay-filter="formDemo" type="button">立即提交</button>
            </div>
        </div>
    </form>
@endsection

@section('script')
    <script charset="utf-8" src="/kindeditor/kindeditor-all-min.js"></script>
    <script charset="utf-8" src="/kindeditor/lang/zh-CN.js"></script>
    <script>
        layui.use(['form', 'layer'], function () {
            var form = layui.form;
            var layer = layui.layer;

            @if($error)
            layer.msg('{{ $error }}', {
                offset: '15px'
                , icon: 2
                , time: 2000
            }, function () {
                location.href = '{{ route('admin.report.index') }}';
            });
            @endif

            form.on('radio(admin)', function (data) {
                if (data.value === '1') {
                    $('#roles').hide();
                } else {
                    $('#roles').show();
                }
            });

            
            $(function () {
                
            });

            //监听提交
            form.on('submit(formDemo)', function (data) {

                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': '{{ csrf_token() }}'
                    }
                });
                var load = layer.load();
                $.post("{{ route('admin.report.update') }}", data.field,
                    function (data) {
                        layer.close(load);
                        if (data.code === 0) {
                            layer.msg('操作成功', {
                                offset: '15px'
                                , icon: 1
                                , time: 1000
                            }, function () {
                                location.href = '{{ route('admin.report.index') }}';
                            });

                        } else {
                            layer.msg(data.msg, {
                                offset: '15px'
                                , icon: 2
                                , time: 2000
                            });
                        }
                    });
            });

        });
    </script>
@endsection